﻿using System;
using Harmonic.Domain;
using Cqrs.Infrastructure;
using Harmonic.CommandHost.Commands;

namespace Harmonic.CommandHost
{
public class CommandHandlers
{
    private readonly IRepository<User> _repository;

    public CommandHandlers(IRepository<User> repository)
    {
        _repository = repository;
    }

    public void Submit(RegisterNewUser registerNewUser)
    {
        User user = new User(registerNewUser.Name, registerNewUser.Email, registerNewUser.Password);
        _repository.Save(user, registerNewUser.OriginalVersion);
    }

    public void Submit(UpgradeUser upgradeUser)
    {
        User user = _repository.GetById(upgradeUser.Id);
        user.UpgradeUser(upgradeUser.Reason);
        _repository.Save(user, upgradeUser.OriginalVersion);
    }

    public void Submit(DeleteUser deleteUser)
    {
        User user = _repository.GetById(deleteUser.Id);
        user.DeleteUser(deleteUser.Reason, DateTime.Now);
        _repository.Save(user, deleteUser.OriginalVersion);
    }

    public void Submit(DowngradeUser deleteUser)
    {
        User user = _repository.GetById(deleteUser.Id);
        user.DowngradeUser(deleteUser.Reason);
        _repository.Save(user, deleteUser.OriginalVersion);
    }

}
}
